
let urls = "http://phpclub.org.cn:8080/api"
$.cookie && ($.cookie.json = true);
$(function () {
    // console.log(123);
    $('.header-1').html(`<div class="w">
        <div class="header-1fl">
            <a href="index.html">小米商城</a><span>|</span>
            <a href="javascript:;">MIUI</a><span>|</span>
            <a href="javascript:;">loT</a><span>|</span>
            <a href="javascript:;">云服务</a><span>|</span>
            <a href="javascript:;">天星数科</a><span>|</span>
            <a href="javascript:;">有品</a><span>|</span>
            <a href="javascript:;">小爱开放平台</a><span>|</span>
            <a href="javascript:;">企业团购</a><span>|</span>
            <a href="javascript:;">资质证照</a><span>|</span>
            <a href="javascript:;">协议规则</a><span>|</span>
            <a href="javascript:;">下载app</a><span>|</span>
            <a href="javascript:;">智能生活</a><span>|</span>
            <a href="javascript:;">Select Location</a>
        </div>
        <div class="header-1fr">
            <a href="login.html">登录</a><span>|</span>
            <a href="register.html">注册</a><span>|</span>
            <a href="">消息通知</a>
            <a href="cart.html"><i class="iconfont icon-gouwuchekong"></i>购物车 (0)</a>
        </div>
    </div>`);
    $('.header-2').html(`<div class="w">
    <div class="loge"><a href=""></a></div>
    <div class="header-nav">
        <a href="">Xiaomi手机</a><a href="">Redmi 手机</a><a href="">电视</a><a href="">笔记本</a><a href="">平板</a><a
            href="">家电</a><a href="">路由器</a><a href="">服务</a><a href="">社区</a>
    </div>
    <div class="header-search">
        <input type="text">
        <input type="submit" class="iconfont" value="&#xe8d6;">
    </div>
</div>`);
    if ($.cookie('user')) {
        $(' .header-1fr a:eq(1) , .header-1fr span:eq(0)').prop('style', 'display:none');
        $('.header-1fr a:eq(0)').html($.cookie('user').nickname).prop('href', 'iCenter.html');
    }
})

/**
 * 获取URL上的指定参数
 * @param {*} key 
 */
function getUrlParam(key) {
    let returnVlue = '';
    location.search.substr(1).split('&').forEach((item) => {
        let keyValue = item.split('=');
        if (keyValue[0] == key) {
            returnVlue = keyValue[1];
        }
    });
    return returnVlue;
}
function times(n) {
    let time;
    let d = new Date();
    d.setTime(n * 1000);
    let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
    let minutes = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
    time = d.getFullYear() + '.' + (parseInt(d.getMonth()) + 1) + '.' + d.getDate() + '--' + hours + ':' + minutes;
    return time;
}

//生成地址栏
function gitAddressList() {
    $.ajax({
        url: urls + '/address/lists',
        data: {
            userId: $.cookie('user').id
        },
        success: function (backData) {
            $('.addressList').html('');
            for (let key in backData.data) {
                $('.addressList').append(`<div class="iCenterBox" addressId="${backData.data[key].id}">
                <div>        
                <span>${backData.data[key].consignee}</span>
                        <span>${backData.data[key].mobile}</span>
                        <span>${backData.data[key].provinceName}</span>
                        <span>${backData.data[key].cityName}</span>
                        <span>${backData.data[key].areaName}</span>
                        <span
                            class="address">${backData.data[key].address}</span>
                            </div> 
                            <div>
                            <span class="addressChange">修改</span>
                            <span class="addressRemove">删除</span>
                            <span>设为默认</span>
                            <input type='checkbox' class='isDefault' isDefault="${backData.data[key].isDefault}">
                        </div>
                    </div>`);
            }
            $('.isDefault').each(function (index, item) {
                if ($(item).attr('isDefault') == '1') {
                    $(item).prop("checked", "true");
                } else {
                    $(item).prop("checked", null);
                }
            })
        }
    })
}